package com.spring.demo.core.event;

import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.spring.demo.core.entity.Order;

@Service
public class OrderPostponedEmailSender implements
		ApplicationListener<OnOrderPostponed> {

	@Async
	@Override
	public void onApplicationEvent(OnOrderPostponed event) {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
		}
		Order order = event.getOrder();
		System.out
				.println("OrderPostponedEmailSender -- Send email to customer: "
						+ order.getCustomer().getId()
						+ " with order status is " + order.getStatus());
	}

}
